//
//  ZJActivityCenterVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/21.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJActivityCenterVC.h"
#import "ZJHBCell.h"
#import "ZJMapVC.h"
#import "locationGPS.h"
#import "LocationManager.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

#import "ZJActivityCell.h"
#import "ZJACModel.h"
#import "ZJActivityVC.h"
#import "ZJHongBaoVC.h"
@interface ZJActivityCenterVC ()<UITabBarDelegate,UITableViewDataSource,UIActionSheetDelegate>{
    double currentLng;
    double currentLat;
}

@property (strong, nonatomic) NSString *HBAddress;
/**<模型数组>*/
@property (nonatomic,strong) NSMutableArray *dataArr;
@end

@implementation ZJActivityCenterVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self sendRequest];
}
- (void)viewDidLoad {
    [super viewDidLoad];
     [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ZJActivityCell class]) bundle:nil] forCellReuseIdentifier:@"ZJActivityCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

-(void)sendRequest{

    NSDictionary *parameter = [LRNetwork requestParameter:@{}];
    NSString *url = [LRNetwork requestURL:@"cgi/activity.php"];
    
    [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {
        
        self.dataArr = [ZJACModel mj_objectArrayWithKeyValuesArray:returnValue[@"activity"]];
        [self.tableView reloadData];
    } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
        [HUD showErrorMsg:errorMessage];
    } withFailureBlock:^{
        
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [tableView tableViewDisplayWitMsg:kNoDataImgName ifNecessaryForRowCount:self.dataArr.count];
    
    return self.dataArr.count + 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {

        ZJHBCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJHBCell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }else{
        ZJActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJActivityCell" forIndexPath:indexPath];
        ZJACModel * model = self.dataArr[indexPath.row - 1];
        cell.tag = indexPath.row;
        cell.model = model;
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        if (!lucky_package[@"title"]) {
            return 0;
        }else{
        return 230;
        }
    }else{
        
//    ZJACModel * model = self.dataArr[indexPath.row -1];
//    CGFloat height = [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[ZJActivityCell class] contentViewWidth:[Utils cellContentViewWith]];
//    return height;
        
        return 174;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row != 0) {
        ZJActivityVC *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJActivityVC"];
        ZJACModel * model = self.dataArr[indexPath.row -1];
        vc.model = model;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 0){
        ZJHongBaoVC * vc = [[ZJHongBaoVC alloc]init];
        [self presentViewController:vc animated:YES completion:nil];
    }

}

@end
